package com.shuangyuan.demo04;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.HashMap;

public class Test02 {
    public static HashMap<String, Object> hb = new HashMap<>();
//        Document parse = Jsoup.parse(new URL("https://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gb18030&word=%C3%C0%C5%AE&fr=ala&ala=1&alatpl=cover&pos=0&hs=2&xthttps=000000"),3000);
//        System.out.println(parse);

    static {
        try {
            ClassLoader classLoader = Test02.class.getClassLoader();
            URL resource = classLoader.getResource("beanss.xml");
            String path = resource.getPath();
            File file = new File(path);
            Document parse = Jsoup.parse(file, "Utf-8");
            Elements bean = parse.getElementsByTag("bean");
            for (Element element : bean) {
                String id = element.attr("id");
                String aClass = element.attr("class");
                Class<?> aClass1 = Class.forName(aClass);
                Constructor<?> dc = aClass1.getDeclaredConstructor();
                dc.setAccessible(true);
                Object obj = dc.newInstance();
                hb.put(id,obj);

            }
            } catch(Exception e){
                e.printStackTrace();
            }
        }
        public static Object grtBean(String key){
        if (!hb.containsKey(key)){
            return "不符合";
        }
        return hb.get(key);
        }
    }
